<template>
  <amis :amisjson="amisobj"></amis>
</template>
<script setup lang="ts">
const amisobj = {
  title: "药材录入",
  toolbar: [
    {
      type: "button",
      actionType: "dialog",
      label: "新增",
      icon: "fa fa-plus pull-left",
      primary: true,
      dialog: {
        title: "新增",
        body: {
          type: "form",
          name: "sample-edit-form",
          api: "post:/amis/api/sample",
          body: [
            {
              type: "input-text",
              name: "engine",
              label: "Engine",
              required: true,
            },
            {
              type: "divider",
            },
            {
              type: "input-text",
              name: "browser",
              label: "Browser",
              required: true,
            },
            {
              type: "divider",
            },
            {
              type: "input-text",
              name: "platform",
              label: "Platform(s)",
              required: true,
            },
            {
              type: "divider",
            },
            {
              type: "input-text",
              name: "version",
              label: "Engine version",
            },
            {
              type: "divider",
            },
            {
              type: "input-text",
              name: "grade",
              label: "CSS grade",
            },
          ],
        },
      },
    },
    {
      type: "button",
      actionType: "dialog",
      label: "载入",
      icon: "fa fa-plus pull-left",
      primary: true,
      dialog: {
        title: "载入表格",
        body: {
          type: "form",
          api: "/api/system/excel/medic",
          body: [
            {
              type: "input-file",
              name: "file",
              label: "上传表格:",
              accept: "*",
              receiver: "/api/system/excel/medic",
            },
          ],
        },
      },
    },
  ],
  body: {
    type: "crud",
    draggable: true,
    api: "/api/medic/list",
    perPage: 50,
    keepItemSelectionOnPageChange: true,
    maxKeepItemSelectionLength: 11,
    autoFillHeight: true,
    labelTpl: "${id} ${engine}",
    autoGenerateFilter: true,
    bulkActions: [],
    quickSaveApi: "/amis/api/sample/bulkUpdate",
    quickSaveItemApi: "/amis/api/sample/$id",
    filterTogglable: true,
    headerToolbar: [
      "bulkActions",
      {
        type: "tpl",
        tpl: "当前有 ${count} 条数据。",
        className: "v-middle",
      },

      {
        type: "columns-toggler",
        align: "right",
      },
      {
        type: "drag-toggler",
        align: "right",
      },
      {
        type: "pagination",
        align: "right",
      },
    ],
    footerToolbar: [
      "statistics",
      {
        type: "pagination",
        layout: "perPage,pager,go",
      },
    ],
    columns: [
      {
        name: "id",
        label: "ID",
        searchable: {
          type: "input-text",
          name: "id",
          label: "主键",
          placeholder: "输入id",
        },
        fixed: "left",
      },
      {
        name: "name",
        label: "名称",
        fixed: "left",
        searchable: true,
      },
      {
        name: "c1",
        label: "五位",
        width: 100,
      },
      {
        name: "c2",
        label: "四气",
        width: 300,
      }, 
      {
       name: "c3",
        label: "归经",
        width: 300,
      },
      {
        type: "operation",
        label: "操作",
        width: 100,
        buttons: [
          {
            type: "button",
            icon: "fa fa-eye",
            actionType: "dialog",
            tooltip: "查看",
            dialog: {
              title: "查看",
              body: {
                type: "form",
                body: [
                  {
                    type: "static",
                    name: "engine",
                    label: "Engine",
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "static",
                    name: "browser",
                    label: "Browser",
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "static",
                    name: "platform",
                    label: "Platform(s)",
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "static",
                    name: "version",
                    label: "Engine version",
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "static",
                    name: "grade",
                    label: "CSS grade",
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "html",
                    html:
                      "<p>添加其他 <span>Html 片段</span> 需要支持变量替换（todo）.</p>",
                  },
                ],
              },
            },
          },
          {
            type: "button",
            icon: "fa fa-pencil",
            tooltip: "编辑",
            actionType: "drawer",
            drawer: {
              position: "left",
              size: "lg",
              title: "编辑",
              body: {
                type: "form",
                name: "sample-edit-form",
                api: "/amis/api/sample/$id",
                body: [
                  {
                    type: "input-text",
                    name: "engine",
                    label: "Engine",
                    required: true,
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "input-text",
                    name: "browser",
                    label: "Browser",
                    required: true,
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "input-text",
                    name: "platform",
                    label: "Platform(s)",
                    required: true,
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "input-text",
                    name: "version",
                    label: "Engine version",
                  },
                  {
                    type: "divider",
                  },
                  {
                    type: "select",
                    name: "grade",
                    label: "CSS grade",
                    options: ["A", "B", "C", "D", "X"],
                  },
                ],
              },
            },
          },
          {
            type: "button",
            icon: "fa fa-times text-danger",
            actionType: "ajax",
            tooltip: "删除",
            confirmText: "您确认要删除?",
            api: "delete:/amis/api/sample/$id",
          },
        ],
        toggled: true,
      },
    ],
  },
};
</script>

<style></style>
